#!/bin/bash
#function  check   file1  and file2    use  their md5 
#support   folder $1 为软件更新目录 $2为更新软件目录

if [[ $# != 2 ]]; then
    echo "usage: sh is_same.sh <dir1> <dir2>"
    exit 1
fi

#遍历文件夹一
cd $1
find  ./ -type f  -print | xargs md5sum  > /tmp/md5.1
cd /tmp
cat md5.1 | sort > md5.1.1
rm md5.1  
mv   md5.1.1  md5.1

#遍历文件夹二
cd $2
find ./ -type f -print | xargs md5sum > /tmp/md5.2
cd /tmp
cat md5.2 | sort > md5.2.1
rm md5.2
mv md5.2.1  md5.2
# if  file1 and file2 is same ,then   print  It is OK  
# else  if  file1 and file2 is different ,then print  They are different
if [ -z "`diff md5.1 md5.2`" ] ;then
        echo "文件夹文件一致";
else
        echo "文件夹文件不一致,将更新文件lib拷贝文件到启动lib";
		cp -r  $1/* $2
fi
rm /tmp/md5.1
rm /tmp/md5.2